<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="设备编号" prop="devicecode">
        <el-input
          v-model="queryParams.devicecode"
          placeholder="请输入设备编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>



    <el-table v-loading="loading" :data="deviceList" @selection-change="handleSelectionChange">
      <el-table-column label="设备编号" align="center" prop="devicecode" />
       <el-table-column label="设备型号" align="center" prop="devicemodel" />
      <el-table-column label="设备类别" align="center" prop="devicetype" />
      <el-table-column label="科室/部门" align="center" prop="useoffice" :formatter="useofficeFormat" />
      <el-table-column label="运维费用" align="center" prop="operationcost" />
      <el-table-column label="折旧费用" align="center" prop="depreciationcost" />
      <el-table-column label="保修费用" align="center" prop="guaranteecost" />
       <el-table-column label="维修费用" align="center" prop="repaircost" />
      <el-table-column label="检定费用" align="center" prop="checkcost" />
      <el-table-column label="保养费用" align="center" prop="takecarecost" />
      <el-table-column label="运营相关费用" align="center" prop="operatecost" />
      <el-table-column label="附加费用" align="center" prop="othercost" />

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { zyxDeviceCostlist, getDevice, delDevice, addDevice, updateDevice, exportDevice,changeDeviceStatus } from "@/api/zyx/device";
import { listMyDept,  } from "@/api/system/dept";

export default {
  name: "Device",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备基础信息表格数据
      deviceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 设备类别字典字典
      devicetypeOptions: [],
      // 使用科室字典字典
      useofficeOptions: [],
      // 安装日期时间范围
      daterangeInstalldate: [],
      // 是否保养字典字典
      istakeOptions: [],
      // 是否检定字典
      ischeckOptions: [],
      // 是否建立档案字典
      isrecordOptions: [],
      // 是否调拨字典
      isallotOptions: [],
      // 是否合算运维字典
      isoperationOptions: [],
      // 风险等级字典
      dangerlevelOptions: [],
      // 是否投保字典
      isinsureOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        devicecode: null,
        devicetype: null,
        devicemodel:null,
        useoffice: null,
        installdate: null,
        factory: null,
        supplier: null,
        dutyuser: null,
        istake: null,
        ischeck: null,
        isrecord: null,
        isallot: null,
        isoperation: null,
        dangerlevel: null,
        propertycode: null,
        leavecode: null,
        propertyvalue: null,
        depreciationyear: null,
        isinsure: null,
        warrantyprice: null,
        warrantyperiod: null,
        insuredunit: null,
        mobile: null,
      },
      // 表单参数
      form: {},

    };
  },
  created() {

    this.getList();
    this.getDicts("zyx_devicetype").then(response => {
      this.devicetypeOptions = response.data;
    });
    // this.getDicts("zyx_dutyoffices").then(response => {
    //   this.useofficeOptions = response.data;
    // });
    listMyDept({deptType:'2'}).then(response => {
      // console.log(response)
      this.useofficeOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.istakeOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.ischeckOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.isrecordOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.isallotOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.isoperationOptions = response.data;
    });
    this.getDicts("zyx_dangerlevel").then(response => {
      this.dangerlevelOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.isinsureOptions = response.data;
    });

  },
  methods: {


    /** 查询设备基础信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeInstalldate && '' != this.daterangeInstalldate) {
        this.queryParams.params["beginInstalldate"] = this.daterangeInstalldate[0];
        this.queryParams.params["endInstalldate"] = this.daterangeInstalldate[1];
      }
      zyxDeviceCostlist(this.queryParams).then(response => {
        this.deviceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 设备类别字典字典翻译
    devicetypeFormat(row, column) {
      return this.selectDictLabel(this.devicetypeOptions, row.devicetype);
    },
    // 使用科室字典字典翻译
    useofficeFormat(row, column) {
      // console.log(this.selectDeptLabel(this.useofficeOptions, row.useoffice))
      return this.selectDeptLabel(this.useofficeOptions, row.useoffice);
    },
    // 是否保养字典字典翻译
    istakeFormat(row, column) {
      return this.selectDictLabel(this.istakeOptions, row.istake);
    },
    // 是否检定字典翻译
    ischeckFormat(row, column) {
      return this.selectDictLabel(this.ischeckOptions, row.ischeck);
    },
    // 是否建立档案字典翻译
    isrecordFormat(row, column) {
      return this.selectDictLabel(this.isrecordOptions, row.isrecord);
    },
    // 是否调拨字典翻译
    isallotFormat(row, column) {
      return this.selectDictLabel(this.isallotOptions, row.isallot);
    },
    // 是否合算运维字典翻译
    isoperationFormat(row, column) {
      return this.selectDictLabel(this.isoperationOptions, row.isoperation);
    },
    // 风险等级字典翻译
    dangerlevelFormat(row, column) {
      return this.selectDictLabel(this.dangerlevelOptions, row.dangerlevel);
    },
    // 是否投保字典翻译
    isinsureFormat(row, column) {
      return this.selectDictLabel(this.isinsureOptions, row.isinsure);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        departid: null,
        devicecode: null,
        devicetype: null,
        useoffice: null,
        installdate: null,
        factory: null,
        supplier: null,
        dutyuser: null,
        istake: null,
        ischeck: null,
        isrecord: null,
        isallot: null,
        isoperation: null,
        dangerlevel: null,
        propertycode: null,
        leavecode: null,
        propertyvalue: null,
        depreciationyear: null,
        isinsure: null,
        warrantyprice: null,
        warrantydate: null,
        insuredunit: null,
        mobile: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeInstalldate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

  }
};
</script>
